package com.winning.util.excelutil.controller;

import com.winning.util.excelutil.common.controller.BaseController;
import com.winning.util.excelutil.common.dto.BaseProtocolOut;
import com.winning.util.excelutil.common.dto.MediaProtocolIn;
import com.winning.util.excelutil.common.exception.BaseException;
import com.winning.util.excelutil.service.ImportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @作者：caopengfei
 * @时间：2020/2/12
 */
@Slf4j
@RestController
@RequestMapping("import")
public class ImportController extends BaseController {

    @Autowired
    private ImportService importService;

    @PostMapping("excel")
    public BaseProtocolOut importExcel(MultipartFile file){

        try {
            importService.importExcel(file);
        } catch (Exception e) {
            log.error("导入失败:", e);
            throw new BaseException("导入失败：" + e.getMessage());
        }
        return BaseProtocolOut.success("导入成功");
    }
}
